<include file="Public/head"/>
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css"/>
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<style type="text/css">
    .select_model {
        -moz-appearance: none;
        background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}paimai/yunying/images/sanjiao.jpg") no-repeat scroll 115px 5px;
        border: 1px solid #d7d7d7;
        float: left;
        height: 26px;
        line-height: 26px;
        margin-right: 8px;
        margin-left: 10px;
        text-indent: 2px;
        width: 136px;
    }

    .select2-container .select2-choice {
        background: #fff url("{:get_style_cdnurl()}paimai/yunying/images/sanjiao.jpg") no-repeat scroll 132px 5px;
        width: 140px;
    }

    .tanShang .daiJingW {
        padding: 20px 0 0 10px;
    }

    .tanShang .cardealer-convert_info {
        width: 560px;
    }

    .tanShang {
        height: 280px;
    }

    .tanShang .convert_info {
        height: 30px;
        line-height: 30px;
        margin: 0;
        text-align: left;
        overflow: hidden;
    }

    .tanShang .convert_info span {
        width: 150px;
        text-align: right;
        float: left;
        display: block;
    }

    .tanShang .convert_info em {
        color: #20ab4f;
        padding: 0;
        font-size: 14px;
    }

    .tanShang .daiJingW .tipmsg {
        font-size: 14px;
        padding: 10px 40px 0;
    }
</style>
<include file="Public/common_header"/>
<div class="mian">
    <include file="Public/sidebar" menu="clcwht.dhjfddgl"/>
    <div class="mianR">
        <div class="yuyue">
            <ul>
                <li onclick="get_list(1);" class="yuCurrent">已兑换</li>
                <li onclick="get_list(2);">已退回</li>
            </ul>
        </div>
        <div class="yuList">
            <div class="yuSuo clearfix" style="float:left;">
                <input id="status" name="status" type="hidden" value="{$params.status|default=1}"/>
                <input type="text" id="order_no" name="order_no" placeholder="请输入订单号" value="" class="suoDian"
                       style="margin:0px;"/>
                <input type="text" id="uid" name="uid" placeholder="请输入兑换用户ID" value="" class="suoDian"/>
                <input type="text" id="user_name" name="user_name" placeholder="请输入兑换用户" value="" class="suoDian"/>
                <input type="text" id="start_time" name="start_time" value="" readonly placeholder="订单开始时间" style="margin-left: 10px;"/><em></em>
                <input type="text" id="end_time" name="end_time" value="" readonly placeholder="订单结束时间"
                       style="margin-right: 10px;"/>
                <div id="return_time" style="display: none">
                    <br/><br/>
                    <input type="text" id="return_start_time" name="start_time" value="" readonly placeholder="退回开始时间"/><em></em>
                    <input type="text" id="return_end_time" name="end_time" value="" readonly placeholder="退回结束时间"
                           style="margin-right: 10px;"/>
                </div>
                <input type="button" id="search" value="搜索" class="suoSou">
            </div>

            <div class="listBox" id="listBox">

            </div>
        </div>
        <!--退单弹出窗口-->
        <div class="tanShang return_exchange" style="display:none">
            <h3>退回兑换订单</h3>
            <ul class="daiJingW">
                <li class="convert_info">
                    <span>兑换用户：</span>
                    <em id="return_user_name"></em>
                </li>
                <li class="convert_info">
                    <span>订单积分：</span>
                    <em id="return_score"></em>
                </li>
                <li class="clearfix tipmsg"></li>
                <li class="clearfix">
                    <input type="hidden" name="con_id" id="con_id">
                    <input type="button" value="确定" class="queding" id="qd_return_user_exchange"/>
                    <input type="button" value="取消" class="quxiao"/>
                </li>
            </ul>
        </div>
        <div class="clear"></div>
    </div>
</div>

<script type="text/javascript">

    function return_user_exchange(id) {
        $.post('/UserExchange/userExchangeInfoJson', {'id': id}, function (data) {
            $("#return_user_name").html(data.user_name);
            $("#return_score").html(data.score);
            $("input[name='con_id']").val(id);
            var str = '确定将以上兑换订单退回吗？';
            $('.tipmsg').html(str);
            $('.return_exchange').show();
        }, 'json');
    }

    $('#qd_return_user_exchange').click(function () {
        var id = $('#con_id').val();
        $(".yunBei").css("display", "block").unbind('click')
        $(".loading").fadeIn();
        $.post('/UserExchange/returnUserExchange', {'id': id}, function (data) {
            if (data.code == 200) {
                $('.set_user_status').hide();
                btn_alert(data.msg);
                setTimeout(function () {
                    window.location.reload();
                }, 300);
            } else {
                $(".loading").fadeOut();
                shibai_alert(data.msg);
            }
        }, 'JSON');
    });


    $("#start_time").ymdateplugin({
        changeMonth: true,
        changeYear: true
    });
    $("#end_time").ymdateplugin({
        changeMonth: true,
        changeYear: true
    });
    $("#return_start_time").ymdateplugin({
        changeMonth: true,
        changeYear: true
    });
    $("#return_end_time").ymdateplugin({
        changeMonth: true,
        changeYear: true
    });

    function get_page(p) {
        var status = $("#status").val();
        var url = get_url();
        url += "&p=" + p;
        $.get("/UserExchange/userExchangeList?status=" + status, encodeURI(url), function (data) {
            $("#listBox").html(data);
        }, "html");
    }
    get_list(1);
    function get_list(status) {
        change_tabs(status);
        $("#status").val(status);
        var url = get_url();
        $.get("/UserExchange/userExchangeList?status=" + status, url, function (data) {
            $("#listBox").html(data);
        }, "html");
    }
    function get_url() {
        var status = $("#status").val();
        var url = "";
        var order_no = $("#order_no").val();
        var user_name = $("#user_name").val();
        var uid = $("#uid").val();
        var start_time = $("#start_time").val();
        var end_time = $("#end_time").val();
        if (status == 2) {
            var return_start_time = $("#return_start_time").val();
            var return_end_time = $("#return_end_time").val();
            if (return_start_time) {
                url += '&return_start_time=' + return_start_time;
            }
            if (return_end_time) {
                url += '&return_end_time=' + return_end_time;
            }
        }
        if (order_no) {
            url += '&order_no=' + order_no;
        }
        if (user_name) {
            url += '&user_name=' + user_name;
        }
        if (uid) {
            url += '&uid=' + uid;
        }
        if (start_time) {
            url += '&start_time=' + start_time;
        }
        if (end_time) {
            url += '&end_time=' + end_time;
        }
        return url;
    }
    function change_tabs(status) {
        if (status == 2) {
            $("#return_time").show();
        } else {
            $("#return_time").hide();
        }
        if ($("#status").val() != status) {
            clear_form_params();
        }
    }

    $('#search').on('click', function () {
        var status = $("#status").val();
        get_list(status);
    });

    function clear_form_params() {
        $(':input').not(':button, :submit, :reset, :hidden, select').val('');
        if ($("#location_area option").length > 1) {
            $("#location_area").val(0);
        }
    }
</script>
<include file="Public/foot"/>